/**
 * 
 */
package com.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.entity.User;
import com.entity.UserOauth;
import com.exception.ServiceException;
import com.mapper.UserMapper;
import com.mapper.UserOauthMapper;
import com.wcansoft.baseWeb.mybatis_plugin.dao.MybatisBaseDAO;
import com.wcansoft.baseWeb.mybatis_plugin.service.BaseService;

/**
 * 
 *
 *@类名称：UserService.java
 *@类描述：用户服务
 *@创建人：zhongy
 *@创建时间：2017年5月4日-下午9:45:54
 *@修改备注:
 *@version
 */
@Component("userService")
public class UserService  extends BaseService<User>{

	@Resource
	private UserMapper userMapper;
	@Resource
	private UserOauthMapper userOauthMapper;
	
	
	public static final long refundDisDays=45;//45天
	public static final long dayMills=1000*3600*24;//45天
	static Logger log = Logger.getLogger(UserService.class);
	
	private static final int GROUTHPOINTS = 1;
	
	 

	
	

		
		 
		
	public User getUserByCookie(Long uid, Integer type, String oauth, String token) throws ServiceException {
		switch (type) {
		case 1:
		case 2:
			return userMapper.getUserByUidPasswd(uid, token);
		case 3: {
			List<UserOauth> list = userOauthMapper.getUserOauth(uid, oauth);
			if (list != null && list.size() > 0) {
				for (UserOauth uo : list) {
					if (token.equalsIgnoreCase(uo.getToken())) {
						return userMapper.get(User.class,uid);
					}
				}
			}
			break;
		}
		}
		return null;
	}
	
	
	
	@Override
	public MybatisBaseDAO<User> getImpDao() {
		return userMapper;
	}

	@Override
	public Class<?> getClazz() {
		return User.class;
	}
	
	
	
		
}
